// house_pkg/pages/room/index.ts
Page({
  /**
   * 页面的初始数据
   */
  data: {
    point: '',
    buildings: '',
    rooms: []
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad ({ point, buildings }) {
    const rooms = []
    // 随机生成房间
    const length = this.getRandom(1, 20)
    // 便利房间
    for (let i = 0; i < length; i++) {
      // 随机生成层数
      const floor = this.getRandom(1, 32)
      // 随机生成房间
      const No = this.getRandom(1, 7)
      // 房间号
      const room = `${floor}0${No}`
      //判断有无重复 加入数组
      if (!rooms.includes(room)) {
        rooms.push(room)
      }

      // 排序
      rooms.sort((a, b) => {
        return a - b
      })
    }

    this.setData({
      point,
      buildings,
      rooms
    })
  },
  getRandom (min, max) {
    return Math.floor(Math.random() * (max - min + 1)) + min
  }
})
